package com.whacos.modules.oa.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whacos.common.enums.Constant;
import com.whacos.common.shiro.ShiroUtils;
import com.whacos.modules.oa.dao.NotifyRecordDao;
import com.whacos.modules.oa.entity.NotifyRecord;
import com.whacos.modules.oa.service.NotifyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xiongdun
 * @description 通知通告发送记录
 * @since 2018/11/17 17:11
 */
@Service
public class NotifyRecordServiceImpl extends ServiceImpl<NotifyRecordDao, NotifyRecord> implements NotifyRecordService {

    @Autowired
    private NotifyRecordDao notifyRecordDao;

    @Override
    public boolean changeRead(Long id) {
        NotifyRecord notifyRecord = new NotifyRecord();
        notifyRecord.setNotifyId(id);
        notifyRecord.setUserId(ShiroUtils.getUserId());
        notifyRecord.setReadDate(new Date());
        notifyRecord.setIsRead(Constant.OA_NOTIFY_READ_YES);
        return notifyRecordDao.changeRead(notifyRecord) > 0;
    }

    @Override
    public boolean batchChangeRead(List<Long> idList) {
        boolean result = true;
        for (Long id : idList) {
            result = this.changeRead(id);
        }
        return result;
    }
}
